﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace Aero
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            SetGlass();
        }
        private void SetGlass()
        {
            WinApi.MARGINS margins;
            margins.Top = Padding.Top;
            margins.Bottom = Padding.Bottom;
            margins.Left = Padding.Left;
            margins.Right = Padding.Right;
            WinApi.DwmExtendFrameIntoClientArea(this.Handle, ref margins);
        }
        protected override void OnMouseDown(MouseEventArgs e)//chwytanie na obszarze przeźroczystym
        {
            WinApi.ReleaseCapture();
            WinApi.SendMessage(this.Handle, WinApi.WM_NCLBUTTONDOWN, WinApi.HT_CAPTION, 0);
            base.OnMouseDown(e);
        }
    }
    class WinApi
    {
        [DllImport("dwmapi.dll")]
        internal static extern void DwmExtendFrameIntoClientArea(System.IntPtr hWnd, ref MARGINS pMargins);

        [DllImport("dwmapi.dll")]
        internal static extern void DwmIsCompositionEnabled(ref bool isEnabled);

        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();

        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

        internal struct MARGINS
        {
            public int Left, Right, Top, Bottom;
        }

        public const int WM_NCLBUTTONDOWN = 0xA1;
        public const int HT_CAPTION = 0x2;
    }
}
